import 'package:after_sale_plugin/r.dart';
import 'package:get/get.dart';
import 'package:lx_widgets_library/language/language_util.dart';
import 'package:lx_widgets_library/lx_widgets_library.dart';
import 'package:safemap/safemap.dart';

class ProductModel {
  String name = '';
  String url = '';
  List<ProductSubModel> subModels = [];
  int get count => subModels.length;

  // 是否展开
  RxBool isExpand = false.obs;

  ProductModel.fromMap(Map<dynamic, dynamic> map) {
    SafeMap data = SafeMap(map);
    name = data['name'].string ?? '';
    url = data['url'].string ?? '';
    var list = data['list'].list;
    if (list != null) {
      List<ProductSubModel> temp = [];
      for (var i = 0; i < list.length; i++) {
        temp.add(ProductSubModel.fromMap(list[i]));
      }
      subModels = temp;
    }
  }
}

enum ProductManualType { video, manual, guide }

class ProductSubModel {
  String title = '';
  String content = '';
  String thumbnail = '';
  ProductManualType type = ProductManualType.manual;

  ProductSubModel.fromMap(Map<dynamic, dynamic> map) {
    SafeMap data = SafeMap(map);
    title = data['title'].string ?? '';
    content = data['content'].string ?? '';
    thumbnail = data['preview'].string ?? '';
    int t = data['type'].toInt ?? 0;
    type = t == 0
        ? ProductManualType.manual
        : (t == 1 ? ProductManualType.guide : ProductManualType.video);
  }
}

class ProductManualState {
  RxInt selectedIndex = 0.obs;

  // segment
  final RxList<SegmentModel> segments = <SegmentModel>[
    SegmentModel()
      ..assetPath = R.whell_n_png
      ..title = AppLanguageUtil.to.titleProductWheel,
    SegmentModel()
      ..assetPath = R.scooter_n_png
      ..title = AppLanguageUtil.to.titleProductScooter,
  ].obs;

  // 数据源
  final RxList<ProductModel> productModels = <ProductModel>[].obs;
}
